using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AutoWave : MonoBehaviour
{

    public List<Transform> WaveTrans;
    public List<Transform> WaveBackTrans;
    public float dtMultiplier = 0.1f;

    private List<float> WaveStartOffsets;
    private List<float> WaveOffsets;
    private float StartPos;

    // Start is called before the first frame update
    void Start()
    {
        WaveStartOffsets = new List<float>();
        foreach (var trans in WaveTrans)
        {
            WaveStartOffsets.Add(trans.position.x);
        }
        StartPos = Mathf.Abs(WaveTrans[WaveTrans.Count - 1].localPosition.x);
    }
    private void Awake()
    {
        WaveOffsets = new List<float>();
        foreach (var trans in WaveTrans)
        {
            WaveOffsets.Add(0.0f);
        }
    }

    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < WaveOffsets.Count; i++)
        {
            WaveOffsets[i] = (WaveOffsets[i] + Time.fixedDeltaTime * dtMultiplier) % StartPos;
            float offset = WaveStartOffsets[i] + WaveOffsets[i];
            WaveTrans[i].localPosition = Vector2.right * offset;
            WaveBackTrans[i].localPosition = Vector2.right * offset;
        }
    }
}
